#include "pionek.h"
#include "plansza.h"

Pionek::Pionek(int x, int y, int dir)
    :Figura(x, y, PIONEK)
{
    this->dir = dir;
    this->czyAktywna=true;
    this->Czyruch = 0;
    this->Graf='P';
}

bool Pionek::czyMogeIsc(int x, int y, Plansza * plansza)
{
    if(this->czyAktywna == false)
        return false;

    if(dir == 1) // do gory
    {
        // Bicie w przelocie
        if(plansza->PrevFig->getTyp() == PIONEK && plansza->PrevFig->GetprevY() == 7 && plansza->PrevFig->GetY() == this->y && plansza->PrevFig->GetY()== 5)
            if((plansza->PrevFig->GetX() - this->x == 1) || (plansza->PrevFig->GetX() - this->x == -1))
            {
                plansza->PrevFig->deaktywuj();
                return true;
            }
            // Bicie w przelocie  koniec
        if((y > this->y && (y - this->y) == 1 && x == this->x) || (y == 4 && y > this->y && (y - this->y) == 2 && this->Czyruch == 0 && x == this->x ))
        {
            if(plansza->GetFiguraAt(this->x,this->y+1) != NULL)
                return false;
            else
            return true;
        }
        else
            return false;
    }

    if(dir == 0) // do dolu
    {
        if(plansza->PrevFig->getTyp() == PIONEK && plansza->PrevFig->GetprevY() == 2 && plansza->PrevFig->GetY() == this->y && plansza->PrevFig->GetY()== 4)
            if((plansza->PrevFig->GetX() - this->x == 1) || (plansza->PrevFig->GetX() - this->x == -1))
            {
                plansza->PrevFig->deaktywuj();
                return true;
            }
        if((y < this->y && (this->y - y) == 1 && x == this->x ) || (y == 5 && y < this->y && (this->y - y) == 2 && this->Czyruch == 0 && x == this->x ))
        {
            if(plansza->GetFiguraAt(this->x,this->y-1) != NULL)
                return false;
            else
            return true;
        }
        else
        {
            return false;
        }
    }
}

bool Pionek::czyMogeBic(int x, int y, Plansza * plansza)
{

    if(dir == 1)
    {
        if((y > this->y && (y - this->y) == 1 && x != this->x && ((x - this->x) == 1 || (x - this->x) == -1)))
            return true;
        else
            return false;
    }

    if(dir == 0)
    {
        if((y < this->y && (this->y - y) == 1 && x != this->x && ((x - this->x) == 1 || (x - this->x) == -1 )))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

void Pionek::SetCzyruch(int ruch)
{
    this->Czyruch=ruch;
}

int Pionek::GetCzyruch()
{
    return this->Czyruch;
}

void Pionek::SetPrevCzyruch(int prevCzyruch)
{
    this->PrevCzyruch=prevCzyruch;
}

int Pionek::GetPrevCzyruch()
{
     return this->PrevCzyruch;
}


